import cv2 as cv
import numpy as np


def canny_demo(image):
    blured = cv.GaussianBlur(image,(3,3),0)
    gray = cv.cvtColor(blured,cv.COLOR_BGR2GRAY)

    grad_x = cv.Sobel(image,cv.CV_16SC1,1,0)
    grad_y = cv.Sobel(image,cv.CV_16SC1,0,1)
    # edge = cv.Canny(grad_x,grad_y,50,150)
    edge = cv.Canny(gray,50,150)
    cv.imshow('edge',edge)
    dst = cv.bitwise_and(image,image,mask=edge)
    cv.imshow('bitand',dst)


src = cv.imread('lena.jpg', 1)
cv.namedWindow('demo',cv.WINDOW_AUTOSIZE)
cv.imshow('demo', src)
canny_demo(src)
cv.waitKey(0)
cv.destroyWindow('demo')